//
//  GdMainViewController.m
//  上海杨浦
//
//  Created by FrankChen on 13-5-23.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "GdMainViewController.h"
#import "ZjypMainViewController.h"
#import "GdSubView.h"
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) 
#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))

@implementation GdMainViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [self AddImageView];
    [self addBtnToScrollView:196+diff/3 :@"btn_gywm.png" :1];
    [self addBtnToScrollView:230+diff/3 :@"btn_bbh.png" :2];
    [self addBtnToScrollView:262+diff/3 :@"btn_jszc.png" :3];
    
    [self AddImageView2];
}

-(void)AddImageView{
    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)]autorelease];
    [imageView setImage:[UIImage imageNamed:@"bgImg_gd.png"]];
    [self.view addSubview:imageView];
}

-(void)AddImageView2{
    int diff2=0;
    if (iPhone5) {
        diff2=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff2=diff2+20;
    }
    
//    UIImageView *imageView2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 360+diff2, 320, 52)];
    UIImageView *imageView2=[[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds) - (52 + 50), 320, 52)];
    [imageView2 setImage:[UIImage imageNamed:@"gd_blueImg.png"]];
    imageView2.userInteractionEnabled = YES;
    [self.view addSubview:imageView2];
    
    CGRect frame1=CGRectMake(7, 6, 40, 40);
    CGRect frame2=CGRectMake(60, 6, 40, 40);
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"gd_zjyp.png"] forState:UIControlStateNormal];
    btn1.frame = frame1;
    [btn1 addTarget:self action:@selector(Button7Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"gd_xgxx.png"] forState:UIControlStateNormal];
    btn2.frame = frame2;
    [btn2 addTarget:self action:@selector(Button8Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    [imageView2 addSubview:btn1];
    [imageView2 addSubview:btn2];
    
}

-(void)Button7Clicked{

    
    ZjypMainViewController *zjyp=[[ZjypMainViewController alloc]init];
    if(!IOS_VERSION_7_OR_ABOVE) {
        zjyp.view.frame=CGRectMake(0, -20, 320, 480);
    }
    [self.view addSubview:zjyp.view];
}

-(void)Button8Clicked{

    
    
}

-(void)addBtnToScrollView:(int) y_zuobiao :(NSString *)img :(int)flag{
    CGRect frame=CGRectMake(25, y_zuobiao, 270, 34);
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    btn.frame = frame;
    switch (flag) {
        case 1:
            [btn addTarget:self action:@selector(Button1Clicked) forControlEvents:UIControlEventTouchUpInside];
            break;
        case 2:
        {
            [btn addTarget:self action:@selector(Button2Clicked) forControlEvents:UIControlEventTouchUpInside];
            UIImageView *versionImageView = [[[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 270, 34)] autorelease];
            versionImageView.image = [UIImage imageNamed: img];
            [btn addSubview: versionImageView];
            
            UILabel *versionLabel = [[UILabel alloc] initWithFrame: CGRectMake(160, 2, 100, 30)];
            versionLabel.backgroundColor = [UIColor whiteColor];
            versionLabel.text = @"v1.0.0";
            versionLabel.font = [UIFont systemFontOfSize: 12];
            versionLabel.textAlignment = NSTextAlignmentRight;
            [btn addSubview: versionLabel];
            [versionLabel release];
        }
            
            break;
        case 3:
            [btn addTarget:self action:@selector(Button3Clicked) forControlEvents:UIControlEventTouchUpInside];
            break;
            
    }
    
    [self.view addSubview:btn];
}

-(void)Button1Clicked{
    GdSubView *gywmSubView=[[GdSubView alloc]initWithFrame:CGRectMake(0, 100+diff, 320, 320)];
    [gywmSubView ShowView:1];
    [self.view addSubview:gywmSubView];
}

-(void)Button2Clicked{
    
}

-(void)Button3Clicked{
    GdSubView *gywmSubView=[[GdSubView alloc]initWithFrame:CGRectMake(0, 100+diff, 320, 320)];
    [gywmSubView ShowView:2];
    [self.view addSubview:gywmSubView];
}



@end



